﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SIA.Configurators;

namespace SIA.HwAccess.PLCSiemens
{
    public abstract class S7Signal : HwSignal
    {
        protected IHwAddress _address;

        public IHwAddress Address { get { return _address; } }

        public S7Signal(IDictionaryProperty signalProperty, IHwConnection connection)
        {
            _connection = connection;
            _name = signalProperty["NOMESEGNALE"].PropertyValue;

            eAreaType atype = eAreaType.NONE;
            try
            {
                atype = (eAreaType)Enum.Parse(typeof(eAreaType), signalProperty["AREATYPE"].PropertyValue, true);
            }
            catch { }

            _address = new S7HwAddress(signalProperty["INDIRIZZO"].PropertyValue, atype);
            if (signalProperty.ContainsKey("READWRITE"))
                _readWrite = (eReadWrite)Enum.Parse(typeof(eReadWrite), signalProperty["READWRITE"].PropertyValue,true);
        }

        public override string ToString()
        {
            return this._name +" (" + this._address + "): " + this.Value;
        }      
    }
}
